package com.heo.music.player.dao;

import com.heo.music.player.entity.MusicInfo;
import com.heo.music.player.entity.Playlist;
import com.heo.music.player.entity.Playlist2MusicInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

/**
 * created on 2024-05-12 11:29
 *
 * @author 星天无极
 **/
public interface Playlist2MusicInfoDao extends JpaRepository<Playlist2MusicInfo, Integer> {
    @Query("select t.musicInfo from Playlist2MusicInfo t where t.playlist = ?1")
    List<MusicInfo> findMusicInfoByPlaylist(Playlist playlist);

    boolean existsByPlaylistAndMusicInfo(Playlist playlist, MusicInfo musicInfo);

    Optional<Playlist2MusicInfo> findByPlaylistAndMusicInfo(Playlist playlist, MusicInfo musicInfo);

    void deleteByPlaylist(Playlist playlist);
}
